"""Xilinx-specific Verilog utilities used by the TAPA compiler."""

# Copyright (c) 2024 RapidStream Design Automation, Inc. and contributors.
# All rights reserved. The contributor(s) of this file has/have agreed to the
# RapidStream Contributor License Agreement.

load("@rules_python//python:defs.bzl", "py_library")
load("@tapa_deps//:requirements.bzl", "requirement")
load("//bazel:pytest_rules.bzl", "py_test")

package(
    default_visibility = ["//tapa:__subpackages__"],
)

py_library(
    name = "xilinx",
    srcs = glob(
        ["*.py"],
        exclude = [
            "ast_types.py",
            "ioport.py",
            "module.py",
            "*_test.py",
        ],
    ),
    deps = [
        ":ast_types",
        "//tapa/backend",
        requirement("jinja2"),
        requirement("pyverilog"),
    ],
)

py_library(
    name = "ast_types",
    srcs = ["ast_types.py"],
    deps = [
        requirement("pyverilog"),
    ],
)

py_library(
    name = "ioport",
    srcs = ["ioport.py"],
    deps = [
        ":ast_types",
        "//tapa/common:unique_attrs",
        requirement("pyslang"),
        requirement("pyverilog"),
    ],
)

py_test(
    name = "ioport_test",
    srcs = ["ioport_test.py"],
    deps = [
        ":ioport",
        requirement("pyslang"),
        requirement("pyverilog"),
    ],
)

py_library(
    name = "module",
    srcs = ["module.py"],
    deps = [
        ":ioport",
        "//tapa/backend",
        "//tapa/common:pyslang_rewriter",
        "//tapa/common:unique_attrs",
        "//tapa/verilog",
        requirement("jinja2"),
        requirement("pyslang"),
        requirement("pyverilog"),
    ],
)

py_test(
    name = "module_test",
    srcs = ["module_test.py"],
    data = [
        "//tapa/verilog/xilinx/testdata:LowerLevelTask.v",
        "//tapa/verilog/xilinx/testdata:UpperLevelTask.v",
    ],
    deps = [
        ":ast_types",
        ":module",
        "//tapa:util",
    ],
)
